<!DOCTYPE html>
<html lang="zh_CN">
<head>
    <#-- 包含其他文件的内容 -->
    <#include "../common/header.ftl"/>
    <script>

            $(function () {
                //上架
                $(".upStateBtn").click(function () {
                    var id=$(this).data('id');
                   $.get("/store/updateShelves.do",{shelves:true,id:id},function (data) {
                       if (data.success){
                           alert("执行成功");
                           setTimeout(function () {
                               window.location.reload();
                           },1500)
                       }
                   })
                })
                //下架
                $(".downStateBtn").click(function () {
                    var id=$(this).data('id');
                    $.get("/store/updateShelves.do",{shelves:false,id:id},function (data) {
                        if (data.success){
                            alert("执行成功");
                            setTimeout(function () {
                                window.location.reload();
                            },1500)
                        }
                    })
                })
                //弹出模态框
                $(".showContentBtn").click(function () {
                    $('#editForm')[0].reset();
                    $('#coverImg').attr('src','');
                    var json = $(this).data('json');
                    if (json){
                        $('input[name=id]').val(json.id);
                        $('input[name=picture]').val(json.picture);
                        $('#coverImg').attr('src',json.picture);
                        $('input[name=diseribe]').val(json.diseribe);
                        $('select[name=mail]').val(json.mail);
                        $('input[name=peoples]').val(json.peoples);
                        $('input[name=price]').val(json.price);
                        $('select[name=shelves]').val(json.shelves+'');
                    }
                    $("#inputModal").modal('show');
                })
                //提交表单
                $(".submitBtn").click(function () {
                    $("#editForm").ajaxSubmit(function (data) {
                          handleResult(data);
                    })
                })
            })

    </script>

</head>
<body>

<div class="container " style="margin-top: 20px">
    <#include "../common/top.ftl"/>
    <div class="row">
        <div class="col-sm-3">
            <#-- 往数据模型中填充一个属性 -->
            <#assign menu="store"/>
            <#include "../common/menu.ftl"/>
        </div>
        <div class="col-sm-9">
            <div class="row">
                <div class="col-sm-12">
                    <h1 class="page-head-line">积分商城管理</h1>
                </div>
            </div>
            <!--高级查询--->
            <form class="form-inline" id="searchForm" action="/store/list.do" method="post">
                <input type="hidden" name="currentPage" id="currentPage" value="1">
                <div class="form-group">
                    <label>关键字:</label>
                    <input type="text" class="form-control" name="keyword"
                           value="${(qo.keyword)!}" placeholder="请输入商品描述">
                </div>
                <button id="btn_query" class="btn btn-success">
                    <span class="glyphicon glyphicon-search"></span> 查询
                </button>
                <a role="button" class="btn btn-success showContentBtn">
                    <span class="glyphicon glyphicon-plus"></span> 添加
                </a>
            </form>

            <table class="table table-striped table-hover" >
                <tr>
                    <th>编号</th>
                    <th>商品图片</th>
                    <th>商品描述</th>
                    <th>邮寄方式</th>
                    <th>购买人数</th>
                    <th>价格</th>
                    <th>上下架</th>
                    <th>操作</th>
                </tr>


                <#list pageInfo.list as entity>
                    <tr>
                        <td>${entity_index+1}</td>
                        <td><img src="${entity.picture!}" width="100px"/></td>
                        <td>${entity.diseribe!}</td>
                        <td>${entity.mail!}</td>
                        <td>${entity.peoples!}</td>
                        <td>${entity.price!}</td>
                        <td>${(entity.shelves)?string('上架','下架')}</td>
                        <<td>
                            <a class="btn btn-info btn-xs showContentBtn" data-json='${(entity.json)!}' >
                                <span class="glyphicon glyphicon-pencil"></span> 编辑
                            </a>
                            <a class="btn btn-danger btn-xs downStateBtn"  data-id="${entity.id}" >
                                <span class="glyphicon glyphicon-pencil"></span> 下架
                            </a>
                            <a class="btn btn-danger btn-xs upStateBtn"  data-id="${entity.id}" >
                                <span class="glyphicon glyphicon-pencil"></span> 上架
                            </a>
                        </td>
                    </tr>
                </#list>
            </table>
            <#include "../common/page.ftl"/>
        </div>
    </div>
</div>


<!-- 模态框必须作为body的子标签 -->
<div class="modal fade" id="inputModal" tabindex="-1" role="dialog"
     aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                <h4 class="modal-title" id="myModalLabel">新增/编辑</h4>
            </div>
            <div class="modal-body">
                <form class="form-horizontal" action="/store/saveOrUpdate.do" method="post" id="editForm">
                    <input type="text" name="id" hidden>
                    
                    <div class="form-group">
                        <label class="col-sm-4 control-label">商品图片：</label>
                        <div class="col-sm-6">
                            <img id="coverImg" width="100%"/>
                            <input type="hidden"  name="picture" >
                            <input type="file" class="form-control" name="file" >
                        </div>
                    </div>

                    <div class="form-group" >
                        <label class="col-sm-4 control-label">商品描述：</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" name="diseribe" >
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-4 control-label">邮寄方式：</label>
                        <div class="col-sm-6">
                            <select class="form-control" name="mail" >
                                <option value="包邮">包邮</option>
                                <option value="到付">到付</option>
                            </select>
                        </div>
                    </div>
                    <div class="form-group" >
                        <label class="col-sm-4 control-label">购买人数：</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" name="peoples" >
                        </div>
                    </div>
                    <div class="form-group" >
                        <label class="col-sm-4 control-label">价格：</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" name="price" >
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-4 control-label">上下架：</label>
                        <div class="col-sm-6">
                            <select class="form-control" name="shelves" >
                                <option value="true">上架</option>
                                <option value="false">下架</option>
                            </select>
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">
                    <span class="glyphicon glyphicon-off"></span> 关闭
                </button>
                <button type="button" class="btn btn-primary submitBtn">
                    <span class="glyphicon glyphicon-saved"></span> 保存
                </button>
            </div>
        </div>
    </div>
</div>






</body>
</html>